package com.client.koshercook.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.VerticalPanel;

public class NextBack extends Composite{
	
	private VerticalPanel Vpanel = new VerticalPanel();
	private HorizontalPanel NBpanel = new HorizontalPanel();
	private PushButton back;
	private PushButton next;
	private Image backImage;
	private Image nextImage;
	private HTML pageText;
	
	public NextBack(){
		
		pageText = Client.pageText;
		pageText.setStyleName("generalInfo");
		
		backImage = new Image("back.png");
		nextImage = new Image("next.png");
		
		backImage.setSize("40px", "40px");
		nextImage.setSize("40px", "40px");
		
		back = new PushButton(backImage);
		next = new PushButton(nextImage);
		
		back.setStyleName("empty");
		next.setStyleName("empty");
		
		back.setTitle("לחץ כדי לחזור 10 תוצאות");
		next.setTitle("לחץ כדי להציג 10 תוצאות נוספות");
		
		back.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Client.model.backPage();				//note: adding 1 to page count because end-users more like a count starting from 1
			}
		});
		
		next.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Client.model.nextPage();
			}
		});
		
		NBpanel.setSpacing(6);
		NBpanel.add(back);
		NBpanel.add(next);
		Vpanel.add(pageText);
		Vpanel.add(NBpanel);
		initWidget(Vpanel);
		pageText.setVisible(false);
		back.setVisible(false);
		next.setVisible(false);
	}
	
	public void setBackButtonVisible(boolean visible){
		back.setVisible(visible);
	}
	
	public void setNextButtonVisible(boolean visible){
		next.setVisible(visible);
	}
	
	public void setPageTextVisible(boolean visible){
		pageText.setVisible(visible);
	}
	
	public void hide(){
		setBackButtonVisible(false);
		setNextButtonVisible(false);
		setPageTextVisible(false);
	}
}
